-
-
Notifications
You must be signed in to change notification settings - Fork 76
Generic/Syntax: add support for inspecting code passed via STDIN #1151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic/Syntax: add support for inspecting code passed via STDIN #1151
Conversation
@rodrigoprimo I believe there is still something wrong in the command as the tests do not pass on Windows. Aside from that, could you please rebase this branch on the current |
This commit improves the Generic.PHP.Syntax sniff to make it work when code is passed via STDIN. Before, any code passed this way would cause a false negative as the sniff was not taking into account that `$phpcsFile->getFilename()` might return `STDIN` instead of an actual file name.
b9bb2dc
to
25ad6e2
Compare
I just rebased without changes, and now
I will take a look to understand why the tests are failing on Windows. When I was creating this PR, I checked that the |
@rodrigoprimo Yes, you will probably want to add |
@jrfnl, I added the As far as I could research, it is not straightforward to reliably pipe commands and escape characters when echoing on Windows, so I opted to create a temporary file instead when on this OS, and the file content is passed via |
I've been thinking this over and while I appreciate all the work you've put into this, I have a feeling the Windows vs STDIN issue is theoretical only. PHPCS doesn't currently support PHP_CodeSniffer/src/Config.php Lines 432 to 436 in 368817d
Now, whether that is something which should be fixed or not is outside the scope of this issue. But knowing that What do you think ? |
b2b0d85
to
d19a939
Compare
Good point, I failed to consider that PHPCS currently doesn't support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rodrigoprimo Thanks for updating this PR. Looks good to me now. I've only got a few small nitpicks, but other that, this is good to go.
Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
dd44013
to
13c2a9a
Compare
Thanks for the final remarks, @jrfnl. They are addressed now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these updates @rodrigoprimo ! LGTM. Will merge once the build has passed.
Description
This PR improves the
Generic.PHP.Syntax
sniff to make it work when code is passed via STDIN. Before, any code passed this way would cause a false negative as the sniff was not taking into account that$phpcsFile->getFilename()
might returnSTDIN
instead of an actual file name.Refer to #915 for additional context and testing instructions.
Suggested changelog entry
Fixed: the
Generic.PHP.Syntax
sniff now handles code passed viaSTDIN
correctlyRelated issues/external references
Fixes #915
Types of changes
PR checklist